#include <16F877A.h>

/*========================================== Controller Configuration Settings========================================*/
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

/*============================================= Global Variables======================================================*/


/*===============================================Pin Definitions======================================================*/
#define SELECT 0
#define MOTOR_SW PIN_B7
#define DIRECTION_MOTOR PIN_B6
#define LCD_delay delay_ms

/* ==============================================Inclusion files======================================================*/

#include "24xx512.h"
#include "LCD_INIT.H"



/***************************** Main function *************************************/
void main(void)
{
	unsigned char dat;
   printf("memory pro run");
	LCD_init();

   port_b_pullups(true);
   output_high(DIRECTION_MOTOR);
	LCD_row1(); LCD_puts("Test EEPROM 24xx");
	LCD_row2(); LCD_puts("Waiting...RESULT");

   output_low(DIRECTION_MOTOR);
	LCD_delay(5000);
   LCD_Clear();
   

while(1)
 {

	EEPROM_set(0x00,0x27);	/* Write EEPROM at address 0x0000 */
	LCD_delay(50);			/* Delay for 50 ms */
	dat = EEPROM_get(0x00);  	/* Read data at address 0x0000 */
	if (dat==0x27)
	{
   output_low(MOTOR_SW);
		LCD_row1(); LCD_puts("SUCCEESS");
      printf("sucess");
      LCD_Clear();
	}
	else
	{
   output_high(MOTOR_SW);
   printf("fail");
		LCD_row1(); LCD_puts("FAIL!");
      LCD_Clear();
	}

	EEPROM_set(0xFF,0x29);	/* Write EEPROM at address 0xFFFF */
	LCD_delay(50);			/* Delay for 50 ms */
	dat = EEPROM_get(0xFF);  	/* Read data at address 0xFFFF */

	if (dat==0x29)
	{
   output_low(DIRECTION_MOTOR);
		LCD_row2(); LCD_puts("SUCCEESS");
	}
	else
	{
   output_high(DIRECTION_MOTOR);
		LCD_row2(); LCD_puts("FAIL!");
	}
   while(1);
	LCD_delay(2000);
   LCD_Clear();
 }

} /* End main */


